//package com.stmt.stmtdesktop.udp;
//
//import io.netty.bootstrap.Bootstrap;
//import io.netty.channel.ChannelFuture;
//import io.netty.channel.ChannelHandler;
//import io.netty.channel.ChannelInitializer;
//import io.netty.channel.ChannelOption;
//import io.netty.channel.nio.NioEventLoopGroup;
//import io.netty.channel.socket.nio.NioDatagramChannel;
//import io.netty.util.concurrent.DefaultEventExecutorGroup;
//import io.netty.util.concurrent.DefaultThreadFactory;
//import java.net.InetSocketAddress;
//import lombok.RequiredArgsConstructor;
//import lombok.extern.slf4j.Slf4j;
//
///**
// * @author liangbo
// */
//@RequiredArgsConstructor
//public class NettyUdpServer {
//
//  private final ChannelHandler channelHandler;
//
//
//  public void start(InetSocketAddress address) {
//    doStart(address);
//  }
//
//  private void doStart(InetSocketAddress address) {
//    //配置服务端的NIO线程组
//    var bossGroup = new NioEventLoopGroup(2);
//    var workerGroup = new NioEventLoopGroup(4);
//
//    try {
//      Bootstrap bootstrap = new Bootstrap()
//          // 绑定线程池
//          .group(workerGroup)
//          .channel(NioDatagramChannel.class)
//          .localAddress(address)
//          //编码解码
//          .handler(new UdpChannelInitializer())
//          .option(ChannelOption.SO_BROADCAST, true)
//          .option(ChannelOption.SO_RCVBUF, 2048 * 1024)
//          .option(ChannelOption.SO_SNDBUF, 1024 * 1024);
//
//      // 绑定端口，开始接收进来的连接
//      ChannelFuture future = bootstrap.bind(8812).sync();
//      System.out.println("netty upc服务器开始监听端口：" + address.getPort());
//      //关闭channel和块，直到它被关闭
//      future.channel().closeFuture().sync();
//    } catch (Exception e) {
//      e.printStackTrace();
//      bossGroup.shutdownGracefully();
//      workerGroup.shutdownGracefully();
//    }
//  }
//
//  @RequiredArgsConstructor
//  public static class UdpChannelInitializer extends ChannelInitializer<NioDatagramChannel> {
//    private static final DefaultEventExecutorGroup GROUP = new DefaultEventExecutorGroup(500, new DefaultThreadFactory("channel-t", true));
//
//
//
//    @Override
//    protected void initChannel(NioDatagramChannel socketChannel) {
////      socketChannel.pipeline().addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
////      socketChannel.pipeline().addLast("encoder", new StringEncoder(StandardCharsets.UTF_8));
//      socketChannel.pipeline().addLast(GROUP, new NettyUdpServerHandler());
//    }
//  }
//
//}